/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28463
 * Date: 2022—06—19
 * Time: 18:29
 */

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

@WebServlet("/listCart.jsp")
public class ListcartServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter out= resp.getWriter();

        HttpSession session= req.getSession();
        ArrayList<Book> cart=(ArrayList<Book>)session.getAttribute("cart");
        if(cart==null){
            out.println("<h2>暂时还没有购物车数据。</h2>");

        }
        else{
            for(Book bk:cart){
                out.println("<h2>"+bk.getName()+" "+bk.getPrice()+"</h2>");
            }
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}